import {AxiosResponse} from "axios";
import {Result} from "@/types/api-common";
import api from "./init";
import {DeviceLoginInfo, DeviceLoginInfoUpdateDTO} from "@/types/device";

/**
 * 获取所有登陆设备信息
 * @returns {Promise<AxiosResponse<Result<LoginHistory[]>>>}
 */
export const getDeviceInfos  = (): Promise<AxiosResponse<Result<DeviceLoginInfo[]>>> => {
    return api.get("/device");
};

/**
 * 更新指定设备信息
 * @param updateParams 更新参数
 * @returns {Promise<AxiosResponse<Result<DeviceLoginInfo>>>}
 */
export const updateDeviceInfo = (updateParams: DeviceLoginInfoUpdateDTO): Promise<AxiosResponse<Result<any>>> => {
    return api.put("/device/update", updateParams);
}

/**
 * 删除指定设备
 * @param deviceId 设备ID
 * @returns {Promise<AxiosResponse<Result<any>>>}
 */
export const deleteDevice = (deviceId: string): Promise<AxiosResponse<Result<any>>> => {
    return api.delete(`/device/delete/${deviceId}`);
};

/**
 * 批量删除指定设备
 * @param deviceIds 设备ID
 * @returns {Promise<AxiosResponse<Result<any>>>}
 */
export const deleteBatchDevice = (deviceIds: string[]): Promise<AxiosResponse<Result<any>>> => {
    return api.delete("/device/deletebatch",{
        data: deviceIds
    });
};

/**
 * 清空除本机外所有设备
 * @returns {Promise<AxiosResponse<Result<any>>>}
 */
export const clearDevices = (): Promise<AxiosResponse<Result<any>>> => {
    return api.delete("/device/clear");
};